package exam.model.dao;

import java.util.HashMap;
import java.util.List;

import exam.common.util.NullCheckUtil;
import exam.model.entity.TExaminationEntity;

public class ExaminationDAO extends AbstractDao<TExaminationEntity>{
	
	public ExaminationDAO() {
		super(TExaminationEntity.class);
	}
	
	public List<TExaminationEntity> selectListExamination() {
		String query = "select e from TExaminationEntity e left outer join e.subQuestionEntity";
		return super.selectList(query);
	}
	

	public TExaminationEntity selectByPk(long id) {
		String query = "select e from TExaminationEntity e left outer join e.subQuestionEntity where e.examId=:examId";
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("examId", id);
		return super.jdbcManager.executeByQueryParams(query, params).getSingleResult();
	}
	
	public TExaminationEntity selectByCd(String cd) {
		String query = "select e from TExaminationEntity e where e.examCd=:examCd";
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("examCd", cd);
		return super.jdbcManager.executeByQueryParams(query, params).getSingleResult();
	}
	
	public boolean insertExamination(TExaminationEntity exam) {
		super.insert(exam);
		return true;
	}
	
	public void updateExamination(TExaminationEntity exam) {
			super.update(exam);
	}
	
	public boolean deleteExamination(long id) {
		if (NullCheckUtil.isNUll(selectByPk(id))) {
			return false;
		}
		super.delete(id);
		return true;
	}
}
